gdk/wayland: Avoid relayout with the same properties
authorJonas Ådahl <jadahl@gmail.com>
Fri, 21 Feb 2020 20:30:42 +0000 (21:30 +0100)
committerJonas Ådahl <jadahl@gmail.com>
Fri, 21 Feb 2020 20:55:16 +0000 (21:55 +0100)
When a popup is already showing, and gdk_surface_present_popup() is
called, if the layout didn't change, we're not really interested in
relayouting.

In the future, we'll be able to get notified if position of the popup
would change by some environmental changes, but until then, just don't
support it.

gdk/gdkpopuplayout.c
gdk/gdkpopuplayout.h
gdk/wayland/gdksurface-wayland.c

index 4509944c555bc168c83bd27a67a821977011d994..f612efb7274564ae43ad5684f6ac53c52d1c1712 100644 (file)
@@ -129,6 +129,31 @@ gdk_popup_layout_copy (GdkPopupLayout *layout)
   return new_layout;
 }
 
+/**
+ * gdk_popup_layout_equal:
+ * @layout: a #GdkPopupLayout
+ * @other: another #GdkPopupLayout
+ *
+ * Check whether @layout and @other has identical layout properties.
+ *
+ * Returns: %TRUE if @layout and @other have identical layout properties,
+ * otherwise %FALSE.
+ */
+gboolean
+gdk_popup_layout_equal (GdkPopupLayout *layout,
+                        GdkPopupLayout *other)
+{
+  g_return_val_if_fail (layout, FALSE);
+  g_return_val_if_fail (other, FALSE);
+
+  return (gdk_rectangle_equal (&layout->anchor_rect, &other->anchor_rect) &&
+          layout->rect_anchor == other->rect_anchor &&
+          layout->surface_anchor == other->surface_anchor &&
+          layout->anchor_hints == other->anchor_hints &&
+          layout->dx == other->dx &&
+          layout->dy == other->dy);
+}
+
 /**
  * gdk_popup_layout_set_anchor_rect:
  * @layout: a #GdkPopupLayout
index 9a07c0aeeafc74a0a75cd4ad44c5e2da2b879131..7427cdb426b15b958df5a480d15d2fecc8eb1c14 100644 (file)
@@ -93,6 +93,10 @@ void                    gdk_popup_layout_unref                  (GdkPopupLayout
 GDK_AVAILABLE_IN_ALL
 GdkPopupLayout *        gdk_popup_layout_copy                   (GdkPopupLayout         *layout);
 
+GDK_AVAILABLE_IN_ALL
+gboolean                gdk_popup_layout_equal                  (GdkPopupLayout         *layout,
+                                                                 GdkPopupLayout         *other);
+
 GDK_AVAILABLE_IN_ALL
 void                    gdk_popup_layout_set_anchor_rect        (GdkPopupLayout         *layout,
                                                                  const GdkRectangle     *anchor_rect);
index 52b85f42336296b969ab9daa613fc9ceed79bbdd..2174bdf72a481905e6e8468b6cad82b770c357f3 100644 (file)
@@ -2819,6 +2819,11 @@ gdk_wayland_surface_present_popup (GdkSurface     *surface,
     }
   else
     {
+      if (impl->popup.unconstrained_width == width &&
+          impl->popup.unconstrained_height == height &&
+          gdk_popup_layout_equal (impl->popup.layout, layout))
+        return TRUE;
+
       reposition_popup (surface, width, height, layout);
     }